import { loginAPI } from "@/api/user";
import {setToken, getToken, removeToken } from "@/utils/auth";

const state = () => {
  return{
    token:getToken()
  }
};
const mutations ={
   setToken(state,token){
     state.token=token
     setToken(token)
   },
   removeToken(state){
    state.token=null
    removeToken()
   }
}
const actions={
  async loginAsync({commit},data){
    let result = await loginAPI(data)
    console.log(result,111);
    commit('setToken',result.data.data.token)
    console.log(result.data.data.token);
  },
  // 退出
  loginout({commit}){
    commit('removeToken')
  }
}
export default {
  namespaced: true,
  state,
  actions,
  mutations,
};
